package com.ibm.ems.servlets;

import com.ibm.ems.dao.PromotionDAO;
import com.ibm.ems.dto.PromotionBean;
import com.ibm.ems.util.ConnectionUtil;
import com.ibm.ems.util.DateUtil;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class GetEvent
 */
public class GetPromotion extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public GetPromotion() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		System.out.println("hi hi hihih");
		Connection conn = ConnectionUtil.getConnection();
		PromotionDAO pdao = new PromotionDAO(conn);

		PromotionBean p = new PromotionBean();

		String idString = request.getParameter("PromotionId");
		p.setProId(idString);
		
		String Name = request.getParameter("PromotionCode");
		p.setProCode(Name);
		
		String d = request.getParameter("day");
		String m = request.getParameter("month");
		String y = request.getParameter("year");
		String d1 = request.getParameter("day1");
		String m1 = request.getParameter("month1");
		String y1 = request.getParameter("year1");

		String Sdate = new String(d + "/" + m + "/" + y);
		p.setSDate(DateUtil.convertStringToDate(Sdate));

		String Edate = new String(d1 + "/" + m1 + "/" + y1);
		p.setEDate(DateUtil.convertStringToDate(Edate));
		p.setDisPercentage(request.getParameter("Discount"));
		
		

		try {
			pdao.CreatePromotion(p);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
finally{
	RequestDispatcher rd=request.getRequestDispatcher("/AdminHome.jsp");
}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	

}
